import Vue from 'vue'
import Vuex from 'vuex'
import {getCartList} from "../api/index.js";
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
	  cartData:[]
  },
  getters:{
	  goodsCount:(state)=>{
		  return state.cartData.reduce((result,item)=>{
			  return result+item.goodsCount;
		  },0)
	  }
  },
  mutations: {
	  changecartData(state,val){
		  val.map(item=>{
			  item.checked=true;
			  return item;
		  })
		  state.cartData=val;
	  }
  },
  actions: {
	  asyncgetCartList(content){
		  getCartList().then(data=>{
			  if(data.resultCode==200){
				  content.commit("changecartData",data.data||[]);
			  }
			 // console.log(data);
		  })
	  }
  },
  modules: {
  }
})
